const moment = require('moment');
module.exports = app => {
  const {
    STRING,
    INTEGER,
    DATE
  } = app.Sequelize; //获取数据类型
  const Users = app.model.define('users', {
    id: {
      type: INTEGER,
      primaryKey: true,
      autoIncrement: true
    },
    username: {
      type: STRING,
      allowNull: false
    },
    password: {
      type: STRING,
      allowNull: false
    },
    nickname: {
      type: STRING,
      allowNull: true
    },
    desc: {
      type: STRING,
      allowNull: true
    },
    cover: {
      type: STRING(1000),
      allowNull: true
    },
    hot: {
      type: INTEGER,
      allowNull: true,
      defaultValue: 0 // 是否属于热门用户  0：不是  1：是
    },
    type: {
      type: INTEGER,
      allowNull: true,
      defaultValue: 1 // 1：前台  2：后台
    },
    create_time: {
      type: DATE,
      allowNull: true,
      get() {
        return moment(this.getDataValue('create_time')).format('YYYY-MM-DD HH:mm:ss');
      }
    },
    update_time: {
      type: DATE,
      allowNull: true,
      get() {
        return moment(this.getDataValue('create_time')).format('YYYY-MM-DD HH:mm:ss');
      }
    }
  }, {
    freezeTableName: true,
    createdAt: 'create_time',
    updatedAt: 'update_time',
    deletedAt: false,
    paranoid: false
  })
  return Users
}